# 案例:
try:
    # 打开文件-只读
    f = open('demo1.txt', mode='r', encoding='utf8')
except FileNotFoundError as e:
    f = open('demo1.txt', mode='w', encoding='utf8')
else:
    # 操作文件-读取内容
    print(f.read)
finally:
    f.close()